<template>
  <view v-if="detial_info.goods_name">
  <view >
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="swiperList">
      <swiper-item v-for="(item,index) in detial_info.pics" :key="index">
         <image  :src="item.pics_big" @click="privent(index)"></image>
      </swiper-item>
    </swiper>
  </view>
  <view class="xiangqing">
    <view class="price">
      <text>￥{{detial_info.goods_price}}</text>
    </view>
    <view class="delname">
      <view>{{detial_info.goods_name}}</view>
      <view class="sc">
        <uni-icons type="star" size="18"></uni-icons>
        <text>收藏</text>
      </view>
    </view>
 <view class="yf">快递：免运费</view>
  </view>
  <rich-text :nodes="detial_info.goods_introduce"></rich-text>
  <view class="cartlist">
    <uni-goods-nav :fill="true"  :options="options" :buttonGroup="buttonGroup"  @click="onClick" @buttonClick="buttonClick" />
  </view>
  </view>
</template>

<script>
  import {mapState,mapMutations,mapGetters} from 'vuex'
  export default {
    computed:{
      ...mapState('myCart',['cartList']),
      ...mapGetters('myCart',['total'])
      
    },
    watch:{
      total:{
     
        handler(newVal){
          const result=this.options.find(item=>item.text==='购物车')
          if(result){
           result.info =newVal
          }
        },
        immediate:true
      }
      
    },
    data() {
      return {
        goods_id:'',
        detial_info:{},
         options: [ {
        			icon: 'shop',
        			text: '店铺',
        		
        		}, {
        			icon: 'cart',
        			text: '购物车',
        			info: 2
        		}],
        	    buttonGroup: [{
        	      text: '加入购物车',
        	      backgroundColor: '#ff0000',
        	      color: '#fff'
        	    },
        	    {
        	      text: '立即购买',
        	      backgroundColor: '#ffa200',
        	      color: '#fff'
        	    }
        	    ]
      };
    },
    
   
    onLoad(options){
      
      this.goods_id=options.goods_id
      this.getdelList()
    },
    methods:{
      ...mapMutations('myCart',['getCartList']),
 async    getdelList(){
   const result=await uni.$http. reqgoodsdet(this.goods_id)
   if(result.statusCode!==200){
     return uni.$showmsg()
   }
   result.data.message.goods_introduce.replace(/<img /g,'<img style="display:block;"').replace(/webp/g,'jpg')
   this.detial_info=result.data.message
   
   
     },
     
     privent(index){
       uni.previewImage({
         current:index,
         urls:this.detial_info.pics.map(item=>item.pics_big)
       })
     },
      onClick (e) {
     	   
            if(e.content.text=='购物车'){
         
           
           uni.switchTab({
             url:'../../pages/cart/cart'
           })
            }
     	  },
     	  buttonClick (e) {
     	    console.log(e)
          if(e.content.text=='加入购物车'){
            const goods={
                      goods_id: this.detial_info.goods_id,       // 商品的Id
                       goods_name: this.detial_info.goods_name,   // 商品的名称
                       goods_price: this.detial_info.goods_price, // 商品的价格
                       goods_count: 1,                           // 商品的数量
                       goods_small_logo: this.detial_info.goods_small_logo, // 商品的图片
                       goods_state: true ,
                       
            }
            this.getCartList(goods)
            
          }
     	   
        
     	  }
    }
    
  }
</script>

<style lang="scss">
.swiperList{
  height: 750rpx;
  .swiper-item,image{
    height: 100%;
    width: 100%;
  }
}
.xiangqing{
    padding: 10px 10px;
    .price{
      color: #f10250;
      font-size:18px ;
      
    }
    .delname{
      display: flex;
      justify-content: space-between;
      font-size: 12px;
      padding: 10px 0;
    }
    .sc{
      width: 120px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      border-left: 1px solid #eee;
      color: gray;
      
    }
    .yf{
      font-size: 12px;
      color: gray;
    }
  }
  .cartlist{
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
  }
</style>
